package com.hackordie.daos;

import com.hackordie.commons.authorities.Profile;
import com.hackordie.daos.mappers.ProfileMapper;

public class ProfileDao extends ACommonDao<Profile> {

	@Override
	public boolean create(final Profile entity) {
		final String SQL = "INSERT INTO profiles (idProfile, name, surnames, birthday, gender, avatar) VALUES (?, ?, ?, ?, ?, ?)";
		jdbcTemplate.update(SQL, entity.toArray());
		return true;
	}

	@Override
	public boolean delete(final int idProfile) {
		final String SQL = "DELETE FROM profiles WHERE idProfile = ?";
		jdbcTemplate.update(SQL, idProfile);
		return false;
	}

	@Override
	public boolean update(final Profile entity) {
		final String SQL = "UPDATE profiles SET name = ?, surnames = ?, birthday = ?, gender = ?, avatar = ? WHERE idProfile = ?";
		jdbcTemplate.update(SQL, entity.toArray(), entity.getId());
		return true;
	}

	@Override
	public Profile[] getAll() {
		final String SQL = "SELECT * FROM profiles";
		return jdbcTemplate.query(SQL, new ProfileMapper()).toArray(new Profile[] {});
	}

	@Override
	public Profile get(int idProfile) {
		final String SQL = "SELECT * FROM profiles WHERE idProfile = ?";
		return jdbcTemplate.queryForObject(SQL, new ProfileMapper(), idProfile);
	}

}
